package config

import (
	"encoding/json"
	"log"
	"os"
)

type Config struct {
	Secret        Secret        `json:"secret"`
	ApiSecret     ApiSecret     `json:"apiSecret"`
	PrivateSecret PrivateSecret `json:"privateSecret"`
	DsnPostgre    DsnPostgre    `json:"dsnPostgre"`
	SuperKey      SuperKey      `json:"superkey"`
	Router        Router        `json:"router"`
	DsnMongo      DsnMongo      `json:"dsnMongo"`
}
type Secret struct {
	AppId     string `json:"appId"`
	AppSecret string `json:"appSecret"`
}
type ApiSecret struct {
	Sn  string `json:"sn"`
	Key string `json:"key"`
}
type PrivateSecret struct {
	Sn         string `json:"sn"`
	PrivateKey string `json:"privateKey"`
}
type DsnPostgre struct {
	Host       string `json:"host"`
	UserDbname string `json:"userDbname"`
	User       string `json:"user"`
	Password   string `json:"password"`
	Port       string `json:"port"`
}
type SuperKey struct {
	Key string `json:"key"`
}
type Router struct {
	Picture           string `json:"picture"`
	LocalToPicServer  string `json:"localToPicServer"`
	LocalToUserServer string `json:"localToUserServer"`
	PictureServer     string `json:"pictureServer"`
}
type DsnMongo struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	Database string `json:"database"`
}

var GlobalConfig Config

func init() {
	data, err := os.ReadFile("../../config.json")
	if err != nil {
		log.Fatal(err, "读取config文件错误")
		return
	}
	var config Config
	err = json.Unmarshal(data, &config)
	if err != nil {
		log.Fatal(err, "json解析错误")
		return
	}
	GlobalConfig = config
}
